new Vue({
  el: '#app',
  data() {
    return {
      form: {
        Article_Name: "",
        Category_SerialNumber: "",
        Enterprise_Info_SerialNumber: $.cookie("enterprise"),
        Type: "1",
        token: $.cookie("token"),
        page: 1,			//页数
        limit: 10,			//每页数据条数
      },
      form1: {
        // Article_Name: "",
        hotspot: '1',  //0是消息1消息条数
        Type: "1",   //1是自己0是全部
        Row_Status: '',  //空是全部0是未读1是已读
        token: $.cookie("token"),
        Enterprise_Info_SerialNumber: $.cookie("enterprise"),
        page: 1,			//页数
        limit: 10,			//每页数据条数
      },
      Release: '0',
      badge: '',
      formData: {},
      dialogFormVisible: false,
      Multistage: [{
        id: '',
        Article_SerialNumber: '',
        Unit_Price: '',
        Quantity: '',
      }],
      tableData: [],
      tablePic: [],
      Pic: [],
      loading: false,
      total: 1,
      dialogForm: false,
      title: '',
      multipleSelection: [],
      Enterprise_Info_SerialNumber: $.cookie("enterprise"),
      // orderData:[]
      submissionTime:''
    }
  },
  mounted() {
   
    this.getList(this.form)
    //消息条数
    this.getbadge(this.form1)
    // 获取此刻时间
    this.getNow()
  },
  
  methods: {
    // 获取此刻时间
    getNow(){
      let now = new Date();
      // 格式化时间（可选，根据需求调整格式）
      let formattedTime = now.toLocaleString(); // 包含日期和时间，按照本地格
      // 或者手动格式化时间
      let customFormat = `${now.getFullYear()}-${now.getMonth()+1}-${now.getDate()} ${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`;
      this.submissionTime = customFormat;
    },
    // 展开数据
    expand(row){
      let _this = this;
      $.ajax({
        url: DomainName + '/getGroupSeekTransactionAllAction?token=' +$.cookie('token'),
        type: 'POST',
        data:row.form,
        success: function (res) {
          console.log('我的采购数据',res)
          row.orderData = res.tableData
          row.total=parseInt(res.limit)
          console.log('888',row,res.limit)
        }
      })
      
    },
    onSerach() {				//查询方法
      console.log("搜搜")
    },
    addContract() {
      console.log("跳转")
    },
    reviseEnterprise() {
      window.location.href = './Revise.html'
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
    },
    handleCurrentChange(val) {
      this.form.page = val;
    },
    handlePreview(Article_SerialNumber) {
      this.Pic = []
      this.tablePic.filter(item => {
        return item.Picture_Type == '0' && item.Article_SerialNumber == Article_SerialNumber
      }).forEach(item => {
        this.Pic.push(item.Picture_Url)
      })
    },
    handleCurrentChange1(e,row) {
      console.log('00000000000000000',e)
      row.form.page = e
      this.expand(row)
    },
    handleSizeChange1(e,row) {
      console.log('1111111111111111111111111111',e,row)
     row.form.page = 1
      row.form.limit = e
      this.expand(row)
    },
    // 获取消息列表
    getList(data) {
      let _this = this
      $.ajax({
        type: 'POST',
        data,
        url: DomainName + '/getGroupSeekProcureAllAction',
        success: function (Result) {
          console.log(Result)
          _this.tableData = Result.tableData;

          _this.total = parseInt(Result.limit)
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      })
    },
    // 获取消息条数
    getbadge(data) {
      let _this = this
      $.ajax({
        type: 'POST',
        data,
        url: DomainName + '/getGroupSeekMessageAllAction',
        success: function (Result) {
          // _this.tableData = Result.tableData;
          console.log(Result, 1111)
          _this.badge = Result.limit
          // _this.total = parseInt(Result.limit)
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      })
    },
    //跳转到增加界面
    addEnterprise() {
      window.location.href = './Add.html'
    },
    LookDetail(e,row) {
      console.log('点击按钮',e,row)
          localStorage.setItem('detail', JSON.stringify(row));
          window.location.href = './produre_detail.html?Group_Seek_Transaction_SerialNumber=' +row.Group_Seek_Transaction_SerialNumber
          sessionStorage.setItem("Group_Seek_Transaction_SerialNumber",row.Group_Seek_Transaction_SerialNumber)
          sessionStorage.setItem("Group_Seek_Purchase_SerialNumber",row.Group_Seek_Purchase_SerialNumber)

    }, 
    //操作通过按钮
    Inventory(row) {
      console.log('通过按钮',row)
      this.loading = true
      this.Group_Seek_Transaction_SerialNumber = row.Group_Seek_Transaction_SerialNumber
      let data = {
        Group_Seek_Purchase_SerialNumber: row.Group_Seek_Purchase_SerialNumber,
        Quantity: row.Quantity,
        token:$.cookie("token"),
      }
      console.log('通过按钮data',data)
      this.CheckStock(data)
      // 添加日志
      const rz_data = {Data: JSON.stringify({
        Group_Config_SerialNumber:"", 
        Group_SerialNumber:row.Group_Transaction_SerialNumber, 
        Config:'通过', 
        Group_Type:'0', 
        Enterprise_Info_SerialNumber:$.cookie("token").enterprise
      })}
      this.LogAdd(rz_data)
    },
    // 检验库存
    CheckStock(data){
      // console.log('检验库存data',data)
      let _this = this
      $.ajax({
        type: 'POST',
        data,
        url: DomainName + '/GroupSeekCheckStockAction',
        success: function (res) {
          console.log('检验库存',res)
            console.log(res);
            let data = {
              Group_Seek_Transaction_SerialNumber: _this.Group_Seek_Transaction_SerialNumber,
              Audit_Status: '1',
              Cause: '',
              token: $.cookie("token")
            }
            _this.GroupSeekTransactionExamine(data,'已确认!')
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      })
    },
    // 添加操作日志
     LogAdd(rz_data) {
      $.ajax({
        type: 'POST',
        data:{Data:rz_data},
        url: DomainName + '/setGroupOperationLogAdd?token='+$.cookie("token"),
        success: function (res) {
          console.log('添加操作日志',res)
        },
        complete: function (XMLHttpRequest) {
          this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      })
    },
    //我的采购申请记录通过
    GroupSeekTransactionExamine(data,message){
      let _this = this
      $.ajax({
        type: 'POST',
        data,
        url: DomainName + '/GroupSeekTransactionExamineAction?token='+$.cookie("token"),
        success: function (res) {
          console.log('添加操作日志',res)
          this.loading = false
					_this.getList(_this.form)
					_this.TrackingNumber = false
        },
        complete: function (XMLHttpRequest) {
          _this.loading=false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      })
    },
    // 确认合同按钮
    Confirmcontract(row){
      let _this = this
      _this.loading = true
			_this.Group_Seek_Transaction_SerialNumber = row.Group_Seek_Transaction_SerialNumber
      let data = {
        Group_Seek_Purchase_SerialNumber: row.Group_Seek_Purchase_SerialNumber,
        token:$.cookie("token")
      }
      _this.getGroupSeekProcure(data)
    },
    // 查询采购订单
    getGroupSeekProcure(data){
      let _this = this
      $.ajax({
        type: 'POST',
        data,
        url: DomainName + '/getGroupSeekProcureIDAction?token='+$.cookie("token"),
        success: function (res) {
          console.log('查询采购订单',res)
            console.log(res);
            let obj = {
              // 采购信息表
              group_seek_transaction: {
                group_seek_transaction_paystages: {}
              }
            }
            let Data = {
              Primary_Key: _this.Group_Seek_Transaction_SerialNumber,
              JSONObject: JSON.stringify(obj),
              token:$.cookie("token"), 
            }
            _this.getSubtableInquiry(Data)
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      })
    },
    //根据表名和主子表结构查询出主表和其子表 带原值
    getSubtableInquiry(data){
      let _this = this
      $.ajax({
        type: 'POST',
        data,
        url: DomainName + '/getSubtableInquiryOriginal?token='+$.cookie("token"),
        success: function (res) {
          console.log('getSubtableInquiry原值查询',res)
            res.group_seek_transaction[0].Row_Status = '4'
            let group_seek_message = {
              Group_Seek_Message_SerialNumber: "",
              Group_Seek_Transaction_SerialNumber: res.group_seek_transaction[0]
                .Group_Seek_Transaction_SerialNumber,
              Cause: "确认合同",
              Submission_Time: _this.submissionTime,
              Enterprise_Info_SerialNumber:$.cookie("token").enterprise,
              Seller_Type: "0"
            }
            let Data = {
              Data: JSON.stringify({
                Modify: {
                  group_seek_transaction: [res.group_seek_transaction[0]]
                },
                Add: {
                  group_seek_message: [group_seek_message]
                }
              }),
              token: $.cookie("token"),
            }
            _this.getEdit(Data)
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      })
    },
    // 修改
  getEdit(data){
    let _this = this
      $.ajax({
        type: 'POST',
        data,
        url: DomainName + '/getEditAction?token='+$.cookie("token"),
        success: function (res) {
          console.log('修改getEdit',res)
            _this.loading = false
           
            // 添加日志
            const rz_data = {Data: JSON.stringify({
              Group_Config_SerialNumber:"", 
              Group_SerialNumber:this.Group_Seek_Transaction_SerialNumber, 
              Config:'确认合同', 
              Group_Type:'0', 
              Enterprise_Info_SerialNumber:$.cookie("token").enterprise
            })}
            _this.LogAdd(rz_data)
            _this.getList(_this.form)
          
        },
        complete: function (XMLHttpRequest) {
          _this.loading=false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      })
  },
  // 付款详情跳转页面
  goDetail(e,row){
    console.log('付款详情',row)
    localStorage.setItem('detail', JSON.stringify(row));
    window.location.href = './purchase_order_detail.html?Group_Seek_Transaction_SerialNumber=' +row.Group_Seek_Transaction_SerialNumber
    sessionStorage.setItem("Group_Seek_Transaction_SerialNumber",row.Group_Seek_Transaction_SerialNumber)
    sessionStorage.setItem("Group_Seek_Purchase_SerialNumber",row.Group_Seek_Purchase_SerialNumber)
  },
  },
})

